package service

import (
	"ao/app/dao"
	"ao/app/model"
	"ao/app/request"
	commonApi "ao/common/api"
	"github.com/gogf/gf/errors/gerror"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/os/glog"
)

var DeviceReport = deviceReportService{}

type deviceReportService struct {
	commonApi.CommonBase
}

func (s *deviceReportService) create(req *request.ReportParams) (err error) {
	_, err = g.Model("device_report").Data(req).Insert()
	glog.Infof("res:%v", err)
	return
}
func (s *deviceReportService) List(req *request.DeviceReportSearchReq) (pageSize, total, page int, list []*model.DeviceReport, err error) {
	model := dao.DeviceReport.M
	total, err = model.Count()
	if err != nil {
		g.Log().Error(err)
		err = gerror.New("获取总行数失败")
		return
	}
	if req.CurrentPage == 0 {
		req.CurrentPage = 1
	}
	page = req.CurrentPage
	if req.PageSize == 0 {
		req.PageSize = request.PageSize
	}
	pageSize = req.PageSize
	err = model.Page(page, req.PageSize).OrderDesc("created_at").Scan(&list)
	if err != nil {
		g.Log().Error(err)
		err = gerror.New("获取数据失败")
		return
	}

	return
}
